package com.sms.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sms.dao.IWhiteListDAO;
import com.sms.po.Whitelist;

/**
 * @author 20111009 by cxh
 */
public class WhiteListDAO extends HibernateDaoSupport implements IWhiteListDAO {
	private static final Log log = LogFactory.getLog(WhiteListDAO.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<Whitelist> showAllWhiteList() {
		log.debug("finding all WhiteList instances");
		try{
			return super.getHibernateTemplate().find("from Whitelist");
		}catch(RuntimeException e){
			log.debug("finding all failed:",e);
			throw e;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Whitelist> showAllWhiteListByPage(DetachedCriteria criteria, int start,int limit) {
		log.debug("finding all WhiteList by pages");
		try{
			return super.getHibernateTemplate().findByCriteria(
					criteria, start, limit);
		}catch(RuntimeException e){
			log.debug("finding all WhiteList failed:",e);
			throw e;
		}
	}

	@Override
	public int getAllWhiteListCount(DetachedCriteria criteria) {
		return super.getHibernateTemplate().findByCriteria(criteria).size();
	}

	@Override
	public boolean addWhiteList(Whitelist bl) {
		log.debug("add WhiteList instance...");
		try{
			log.debug("add WhiteList instance success");
			this.getHibernateTemplate().save(bl);
			return true;
		}catch(RuntimeException e){
			log.debug("add WhiteList instance failed:",e);
			throw e;
		}
	}

	@Override
	public boolean removeWhiteList(Whitelist bl) {
		log.debug("remove WhiteList instance...");
		try{
			this.getHibernateTemplate().delete(bl);
			return true;
		}catch(RuntimeException e){
			log.debug("remove WhiteList instance failed:",e);
			throw e;
		}
	}
	
	
	public boolean updateWhiteList(Whitelist bl) {
		log.debug("update WhiteList instance...");
		try{
			this.getHibernateTemplate().update(bl);
			return true;
		}catch(RuntimeException e){
			log.debug("update WhiteList instance failed:",e);
			throw e;
		}
	}

}
